<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'notice-index', //页面标示
    'pagename' => '通知公告', //当前页面名称
    'mycss' => array('content/textlist'), //加载的css样式表
    'myjs' => array(), //加载的js脚本
    'footerjs'=>array('content/fuelux/fuelux', 'content/combodate/moment.min','content/jquery.smoothConfirm'),
    'head' => true, //加载头部文件
);
include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<!-- content -->
<section id="content">
<section class="main padder"> 
<div class="clearfix"> 
<h4><i class="fa fa-edit"></i>通知公告</h4> 
</div> 
<div class="row"> 
<div class="col-sm-12"> 
<section class="panel"> 
<div class="panel-body">
<div class="alert alert-warning alert-block">
      <button data-dismiss="alert" class="close" type="button"><i class="fa fa-times"></i></button>
      <h4><i class="fa fa-bell-o"></i>提示信息</h4>
      <p>1、被动通知会在用户与微信有交互的时候主动推送给用户，每个用户只会收到一次；</p>
      <!-- <p>2、主动群发会消耗公众号每月群发次数，每个用户每月最多可接受4次；</p> -->
      <p>2、根据规定，系统广播只会推送给48小时内与系统有互动的用户；</p>
      <p>3、通知不可编辑，请注意发送请仔细核实内容；</p>
</div> 
  <!--通知公告  b-->
  <div class="alert alert-info" style="font-size:13px"> 
     <button type="button" class="close" data-dismiss="alert"><i class="fa fa-times"></i></button> 
     <i class="fa fa-info-sign fa-lg"></i>
     <strong>剩余发布次数: </strong>
     系统广播：本<?php echo $counts['radio']['type'];?><span class="red"><?php echo $counts['radio']['has'];?></span><?php echo $counts['radio']['unit'];?>
    </div>
  <form class="form-horizontal" id="noticeAddForm" method="post"> 
      <div class="form-group">
          <label class="col-sm-1 control-label" style="width:100px;">通知范围</label>
          <div class="col-sm-4">
              <select id="notice_level" class="form-control" name="notice_level">
              <?php
              if ($noticeLevel){
                  foreach($noticeLevel as $k=>$v){
              ?>
                  <option value="<?php echo $k;?>"><?php echo $v;?></option>
              <?php
                  }
              }
              ?>
              </select>
          </div>
      </div>
      
      <div class="form-group">
          <label class="col-sm-1 control-label" style="width:100px;">通知类型</label>
          <div class="col-sm-7">
          <?php
          foreach($noticeType as $key=>$val){
		  ?>
           <div class="col-xs-2 radio m-l-large"><label class="radio-custom"><input type="radio" name="type" <?php if($key){echo 'checked="checked"';}?> value="<?php echo $key;?>"><i class="fa fa-circle-o <?php if($key){echo 'checked';}?>"></i><?php echo $val;?></label></div>
         <?php }?>
          </div>
      </div>
      <div id="show-times" style="display: none;">
      <div class="form-group">
          <label class="col-sm-1 control-label" style="width:100px;">起止时间</label>
          <div class="col-sm-2">
              <input type="text" id="stime" name="stime" placeholder="必填" data-required="true" class="form-control">
          </div>
          <div class="col-sm-2">
              <input type="text" id="etime" name="etime" placeholder="必填" data-required="true" class="form-control">
          </div>
      </div>
      <div class="form-group">
          <label class="col-sm-1 control-label" style="width:100px;">推送类型</label>
          <div class="col-sm-10"> 
          <?php
              foreach($newsStatus as $key=>$val){
          ?>
          <div class="col-xs-1 radio m-l-large">
            <label class="radio-custom">
              <input type="radio" name="is_open" value="<?php echo $key;?>" <?php if (!$key){echo 'checked';}?>/>
              <i class="fa fa-circle-o <?php if (!$key){echo 'checked';};?>"></i><?php echo $val;?></label>
          </div>
          <?php
              }
          ?>
          <div class="help-block" style="clear:both">不推送的通知只会显示在用户中心的通知列表中</div>
          </div>
      </div>
      </div>
      <div class="form-group">
          <label class="col-sm-1 control-label" style="width:100px;">通知标题</label>
          <div class="col-sm-4">
              <input type="text" id="title" name="title" placeholder="必填" data-required="true" class="form-control">
          </div>
      </div>
      
      <div class="form-group">
          <label class="col-sm-1 control-label" style="width:100px;"></label>
          <div class="col-sm-4">
              <div class="col-xs-4 radio m-l-large"><label class="radio-custom" id="notice_way_id_0" ><input type="radio" name="notice_way" checked="checked" value="0"><i class="fa fa-circle-o checked"></i>普通文本</label></div>
              <div class="col-xs-4 radio m-l-large" id="notice_way_news"><label class="radio-custom" id="notice_way_id_1" ><input type="radio" name="notice_way" value="1"><i class="fa fa-circle-o"></i>图文组合</label></div>
          </div>
      </div>
      
      <div class="form-group" id="show-notice-type-text">
          <label class="col-sm-1 control-label" style="width:100px;">通知方式</label>
          <div class="col-sm-10">
              <p><a href="<?php echo U('face/index',array('id'=>'cont-text'));?>" rel="pop">添加表情</a></p>
              <textarea id="cont-text" name="content" placeholder="通知内容(字数限制在600字以内)"  style="width:80%; height:300px" class="form-control parsley-validated" data-trigger="keyup"></textarea>
          </div>
      </div>
      <div class="form-group" id="show-notice-type-news" style="display:none">
          <label class="col-sm-1 control-label" style="width:100px;">通知方式</label>
          <div class="col-sm-4">
          <select id="cont-news" class="form-control" name="source_id">
          <option value="0">选择图文素材</option>
          <?php
            if ($news){
                foreach($news as $val){
            ?>
          <option value="<?php echo $val['id'];?>"><?php echo $val['title'];?></option>
          <?php
              }
          }else{
              echo '<option value="0">请先添加新闻素材</option>';	
          }
          ?>
              </select>
         </div>
      </div>
      
      <div class="form-group"> 
          <label class="col-sm-1 control-label" style="width:100px;"></label>
          <div class="col-sm-4">
              <button type="submit" id="sub-ok" class="btn btn-primary">保存</button>
              <button type="button" class="btn btn-white col-md-offset-1">取消</button>
              <a class="btn btn-warning col-md-offset-1" style="display:none" href="<?php echo U('notice/send');?>" rel="pop" id="sendMasssend">群发通知</a>
          </div> 
      </div>
  </form>
  <!--通知公告  E-->
</div> 
</section>
</div> 
</div> 
</section>
</section> 
<!--/ content --> 
<!--主体 结束-->
<link rel="stylesheet" media="screen" href="<?php echo PUBLIC_PATH; ?>jquery-ui/css/smoothness/jquery-ui-1.10.0.custom.min.css"/>
<script type="text/javascript" src="<?php echo PUBLIC_PATH; ?>jquery-ui/js/jquery-ui-1.10.0.custom.min.js"></script>
<script type="text/javascript" src="<?php echo PUBLIC_PATH; ?>jquery-ui/js/jquery-ui-timepicker-addon.js"></script>
<script>
var isSending=1;
$(function(){
	$('#stime').datetimepicker();
    $('#etime').datetimepicker();
	
	$('#noticeAddForm').submit(function(){
		var type = $('input[name="type"]:checked').val(); //通知类型
		var way = $('input[name="notice_way"]:checked').val(); //通知方式
		//console.log(type+" "+way);
		if (type==0){
			if (!$('#stime').val()||!$('#etime').val()){
				Msg.error('请设置通知的有效时间');
				resetSubmit("#sub-ok",'提交');
				return false;
			}
			var isdate = checkTime($('#stime').val(),$('#etime').val());
			if(!isdate){
				Msg.error('开始、结束时间填写错误！');
				resetSubmit("#sub-ok",'提交');
				return false;
			}
		}
		if (!$('#title').val()){
			Msg.error('通知标题不能为空！');
			resetSubmit("#sub-ok",'提交');
			return false;
		}
		if(way == 0 && !$('#cont-text').val()){
			Msg.error('通知内容不能为空！');
			resetSubmit("#sub-ok",'提交');
			return false;
		}
		//=====
	  $("#sub-ok").smoothConfirm('<span class="red">提交后不可编辑，确认无误吗？</span>', {
		  width:240,
		  ok: function() {
				Msg.loading();
				$.post('<?php echo U('notice/post');?>',$('#noticeAddForm').serialize(),function(result){
				  Msg.hide();
				  resetSubmit("#sub-ok",'提交');
				  if (result.status==1){
					 if (result.data.masssend==2){
						 $("#sendMasssend").show().click();
						 $('#facebox_overlay').unbind('click');
						 $(document).bind('close.facebox', function() {
							 clearTimeout(isSending);
						});
						 return false;
					}else{
						Msg.ok('添加成功',function(){
							document.location='<?php echo U('notice/index');?>';	 
						},2000);	 
						}  
				}else{
				  Msg.error(result.info);
				}
				},'json');
				return false;
		  },
		  //点击取消返回callback
		  cancel: function() {
			  return false;
		  }
	  });
		//=====
		return false;
	});
	
	$('input[name="notice_way"]').click(function(){
		var val = $(this).val();
		if(val == "0"){
			$("#show-notice-type-text").show();
			$("#show-notice-type-news").hide();
		}else if(val == "2"){
			$("#show-notice-type-text").show();
			$("#show-notice-type-news").hide();
		}else{
			$("#show-notice-type-text").hide();
			$("#show-notice-type-news").show();
		}
	});
	
	$('input[name="type"]').click(function(){
		var val = $(this).val();
		if(val == "0"){
			$("#show-times").show();
			$("#notice_way_news").show();
			$("#show-notice-type-news").hide();
		}else if(val == "2"){
			$("#show-times").hide();
			$("#notice_way_news").show();
			$("#show-notice-type-news").hide();
		}else{
			$("#show-times").hide();
			$("#notice_way_news").hide();
			$("#show-notice-type-news").hide();
			$('#notice_way_id_0').click();
		}
	});
	
	$("#cont-news").change(function(){
		var title='';
		if ($(this).val()>0){
			title=$("#cont-news").find('option:selected').text();
		}
		$("#title").val(title);
	});
})
</script>

<?php
include getTpl('footer', 'public');
?>